package com.immac.leejc.copytimetest;

public class copytimetester {
	private int size = 10000;
	private Integer[] arrInteger1;
	private Integer[] arrInteger2;

	public void setIntegerArray() {
		arrInteger1 = new Integer[size];
		arrInteger2 = new Integer[size];

		for (int i = 0; i < arrInteger1.length; i++) {
			arrInteger1[i] = (Integer) (i + 1);
		}
	}
	
	public void resetIntegerArray() {
		for (int i = 0; i < arrInteger2.length; i++) {
			arrInteger2[i] = null;
		}
	}

	public void copyIntegerArrayUsedFor() {
		for (int i = 0; i < arrInteger1.length; i++) {
			arrInteger2[i] = arrInteger1[i];
		}
	}
	
	public double repeatForCopyTest(int count) {
		long start = System.currentTimeMillis();

		for (int i = 0; i < count; i++) {
			copyIntegerArrayUsedFor();
		}
		
		long end = System.currentTimeMillis();

		return ( end - start )/1000.0;
	}
	
	public void copyIntegerArrayUsedArrayCopy() {
		System.arraycopy(arrInteger1, 0, arrInteger2, 0, size);
	}
	
	public double repeatArrayCopyTest(int count) {
		long start = System.currentTimeMillis();
		
		for (int i = 0; i < count; i++) {
			copyIntegerArrayUsedArrayCopy();
		}
		
		long end = System.currentTimeMillis();

		return ( end - start )/1000.0;
	}
}
